import axios from 'axios';
console.log("后台地址：", localStorage.getItem("WEBIP"));
//定义接口域名
const IP = localStorage.getItem("WEBIP") ? localStorage.getItem("WEBIP") : "http://61.149.254.38:10121";
export default IP;
//添加sessios返回头
axios.defaults.withCredentials = true;
//axios跨域请求数据
function queryAxios(url, payload, method) {
    // const URL = IP + url;
    const URL = 'http://192.168.1.86:3000' + url;
    //分发接口
    if (method === "post" || method === "put") {
        return axios({
            method: method,
            url: URL,
            headers: {'Content-Type': 'application/json'},
            data: JSON.stringify(payload),
            timeout: 5000,
        })
            .then(data => data)
            .catch(e => (e.response))

    } else {
        return axios({
            method: method,
            url: URL,
            timeout: 5000,
            headers: {'Content-Type': 'application/json'},
        })
            .then(data => data)
            .catch(e => (e.response))
    }
}
import Store from './store/store'
const getType = Object.prototype.toString;
const valueType = {arr: [], string: '', obj: {}, num: 13164624108};
export const query = (url, body, method, valType) => {
    console.log("请求方式:", method, "入参url:", url, "入参Body:", body);
    return queryAxios(url, body, method)
        .then(val => {
            if (!val) {return () => console.log("请求未返回数据!!!")}
            console.log('请求成功!!!===>', method + "请求:" + url + "后台相应参数：", val);
            const errOBJ = {
                402: {data: valueType[valType]},
                403: {data: valueType[valType]},
                404: {data: valueType[valType]},
                500: {data: valueType[valType]},
                200: getType.call(val.data) === getType.call(valueType[valType]) ? val : {data: "返回数据类型错误"}
            };
            Store.dispatch({type: "account/ErrCode", payload: val.status ? val.status : val.data.status});
            return errOBJ[val.status ? val.status : val.data.status]
        })
        .catch(err => console.log('请求失败!!!===>store.js===>64行打印错误信息', err))
};

